]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
gdm: Add ability to queue a message overriding ones with less priority
authorMarco Trevisan (Treviño) <mail@3v1n0.net>
Tue, 16 Feb 2021 02:08:38 +0000 (03:08 +0100)
committerRay Strode <halfline@gmail.com>
Tue, 16 Feb 2021 18:00:10 +0000 (18:00 +0000)
There are cases in which a service may want to override a message with
one coming with higher priority, for example an info or hint message
isn't useful anymore if we've already got an error message.

In the same way when a service has been stopped we don't care anymore
showing its info or hint messages, while it still may be relevant to show
errors.

An example is the fingerprint service that may emit errors quickly while
the hints messages should not be kept around when an error is already
queued or when the service has been stopped.

So, add function that allows to override queued messages based by their
type that follows this policy:
 - Messages coming from different services are always preserved in
   their original order.
 - Messages (from the same service) with a priority equal or higher than
   the last queued one are preserved.
 - Messages matching completely the last queued are dropped in favor of
   this one.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1683>

js/gdm/util.js

index 16689f10e6426dc8726312cf8f0f22d88b0426e1..67255bc9e2b16a7493a52ef678a2784fa6b3f254 100644 (file)
@@ -49,10 +49,11 @@ var USER_READ_TIME = 48;
 const FINGERPRINT_ERROR_TIMEOUT_WAIT = 15;
 
 var MessageType = {
+    // Keep messages in order by priority
     NONE: 0,
-    ERROR: 1,
+    HINT: 1,
     INFO: 2,
-    HINT: 3,
+    ERROR: 3,
 };
 
 const FingerprintReaderType = {
@@ -330,6 +331,20 @@ var ShellUserVerifier = class {
         this._queueMessageTimeout();
     }
 
+    _queuePriorityMessage(serviceName, message, messageType) {
+        const newQueue = this._messageQueue.filter(m => {
+            if (m.serviceName !== serviceName || m.type >= messageType)
+                return m.text !== message;
+            return false;
+        });
+
+        if (!newQueue.includes(this.currentMessage))
+            this._clearMessageQueue();
+
+        this._messageQueue = newQueue;
+        this._queueMessage(serviceName, message, messageType);
+    }
+
     _clearMessageQueue() {
         this.finishMessageQueue();